import request from "../utils/request";

export function getRolesList(){
    return request({
        url:'/roles'
    })
}

//根据id删除权限
export function removeRightId(roleId,rightId){
    return request({
      url: `/roles/${roleId}/rights/${rightId}`,
      method: "delete",
    });
}

//添加角色
export function addRole({roleName,roleDesc}){
    return request({
        url:'/roles',
        method:'POST',
        data:{
            roleName,roleDesc
        }
    })
}

//获取当前角色的数据
export function getRolesInfo(id){
    return request({
        url:`/roles/${id}`,
    })
}

//编辑改角色的信息
export function editRoles(id,roleName,roleDesc){
    return request({
      url: `/roles/${id}`,
      method: "PUT",
      data: {
        roleName,roleDesc
      },
    });
}

//获取所有权限列表
export function getTreeData(){
    return request({
        url:'/rights/tree'
    })
}

//分配权限
export function setRoles(roleId,idStr){
    return request({
      url: `/roles/${roleId}/rights`,
      method: "post",
      data: {
        rids: idStr,
      },
    });

}

//根据ID删除角色
export function deleteRoles(id){
    return request({
        url:`/roles/${id}`,
        method:'delete',
    })
}